package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apiguardian.api.API;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

import java.util.List;

/**
 * @ Description: TODO
 * @ BelongsProject: zzyl
 * @ Author: G攀
 * @ CreateTime: 2024-08-25  14:09
 * @ Version: 1.0
 */
@Api(tags = "护理等级相关接口")
@RequestMapping("/nursingLevel")
@RestController
@Slf4j
public class NursingLevelController extends BaseController {

    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 查询所有的护理等级
     */
    @GetMapping("/listAll")
    @ApiOperation("查询所有的护理等级")
    public ResponseResult<List<NursingLevelVo>> getAll() {
        log.info("查询所有的护理等级");
        // 调用业务层查询所有的护理计划并返回
        List<NursingLevelVo> nursingLevelList = nursingLevelService.getAll();
        return ResponseResult.success(nursingLevelList);
    }

    /**
     * 根据ID查询护理等级，回显
     */
    @GetMapping("/{id}")
    @ApiOperation("根据ID查询护理等级")
    public ResponseResult getNursingProjectById(@ApiParam("护理等级ID") @PathVariable Long id) {
        log.info("根据ID查询护理等级：{}", id);
        NursingLevelVo nursingLevelVo = nursingLevelService.getNursingLevelById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    /**
     * 根据ID修改护理等级
     */
    @PutMapping("/update")
    @ApiOperation("修改护理等级接口")
    public ResponseResult update(@ApiParam("修改护理等级接口") @RequestBody NursingLevelDto nursingLevelDto) {
        log.info("修改护理项目:{}", nursingLevelDto);
        nursingLevelService.update(nursingLevelDto);
        return ResponseResult.success();
    }

    /**
     * 根据ID删除护理级别
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除护理级别接口")
    public ResponseResult delete(@PathVariable Long id) {
        log.info("删除护理级别接口：{}", id);
        // 首先判断护理是否为null，为空不能删除
        NursingLevelVo nursingLevel = nursingLevelService.getNursingLevelById(id);
        if (nursingLevel == null) {
            return ResponseResult.error("删除失败，护理级别不存在！");
        }
        // 调用删除逻辑，来删除
        nursingLevelService.delete(id);
        return ResponseResult.success();
    }

    /**
     * 根据ID来启用或者禁用护理级别
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("根据ID禁用或启用护理级别")
    public ResponseResult startOrStop(@PathVariable Long id, @PathVariable Integer status) {
        log.info("根据ID禁用或者启用护理级别：{},{}", id, status);
        // 首先判断护理是否为null，为空不能启用或者禁用
        NursingLevelVo nursingLevelById = nursingLevelService.getNursingLevelById(id);
        if (nursingLevelById == null) {
            return ResponseResult.error("删除失败，护理级别不存在！");
        }
        // 调用逻辑，来禁用或者启用护理项目
        nursingLevelService.startOrStop(id, status);
        return ResponseResult.success();
    }

    /**
     * 添加护理等级信息
     *
     * @param nursingLevelDto
     * @return
     */
    @ApiOperation(value = "添加护理等级信息")
    @PostMapping("/insert")
    public ResponseResult addNursingLevelInfo(@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.addNursingLevelInfo(nursingLevelDto);
        return success();
    }

    /**
     * 分页查询项目等级信息
     *
     * @return
     */
    @ApiOperation(value = "分页查询项目等级信息")
    @GetMapping("/listByPage")
    public ResponseResult<PageResponse<NursingLevelVo>> getNursingLevelByPage(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            String name,
            Integer status
    ) {
        log.info("记录前端请求信息{},{},{},{}", pageNum, pageSize, name, status);
        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.getNursingLevelByPage(pageNum, pageSize, name, status);
        return success(pageResponse);
    }
}